package huoye.shops.huoye.operation.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import javax.xml.XMLConstants;

import huoye.shops.R;
import huoye.shops.base.BaseActivity;
import huoye.shops.base.BaseFragment;
import huoye.shops.base.PullToRefreshFragment;
import huoye.shops.huoye.operation.adapter.UserStatisticsAdapter;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.huoye.operation.model.StatisticsData;
import huoye.shops.huoye.operation.presenter.StatisticsPresenter;
import huoye.shops.huoye.operation.view.IManageEventRefreshView;
import huoye.shops.huoye.operation.view.IStatisticsRefreshView;

import static huoye.shops.huoye.home.fragment.HomeDataShowFragment.PAGE_TYPE_TODAY;

public class StatisticsFragment extends PullToRefreshFragment<StatisticsData> implements IStatisticsRefreshView {


    private int mType;
    private StatisticsPresenter mStatisticsPresenter;

    public StatisticsFragment() {

    }

    @Override
    public RecyclerViewAdapter createAdapter() {
        Bundle bundle = getArguments();
        mType = bundle.getInt(BaseActivity.EXTRAS_KEY_DATA);
        UserStatisticsAdapter adapter = new UserStatisticsAdapter(getActivity());


        return adapter;
    }

    @Override
    public int getContentViewId() {
        return R.layout.fragment_statistics;
    }

    @Override
    protected void initView(View view, @Nullable Bundle bundle) {
        super.initView(view, bundle);
        mStatisticsPresenter = new StatisticsPresenter();
        mStatisticsPresenter.addTaskListener(this);
        mStatisticsPresenter.onStart();
        query();
    }

    @Override
    public void query(Paging paging) {
        super.query(paging);
        if (mType == PAGE_TYPE_TODAY) {
            mStatisticsPresenter.getUserStatisticsList("Today",paging);
        } else {
            mStatisticsPresenter.getUserStatisticsList("All",paging);
        }
    }

    public static Fragment getInstan(int type) {
        StatisticsFragment fragment = new StatisticsFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(BaseActivity.EXTRAS_KEY_DATA, type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onItemClick(StatisticsData statisticsData, int i, View view) {

    }
}

